﻿using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Profiles;

namespace Konekcija.Core.Reporting.Mappings.Profiles
{
    public class CommunicationChannelsMap : ClassMap<CommunicationChannel>
    {
        public CommunicationChannelsMap()
        {
            Schema("profile");
            Table("CommunicationChannels");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            
            Map(x => x.UserId)
                .Not.Insert()
                .Not.Update()
                .Nullable();
            Map(x => x.ProductId)
                .Not.Insert()
                .Not.Update()
                .Nullable();
            Map(x => x.MerchantId)
                .Not.Insert()
                .Not.Update()
                .Nullable();
            Map(x => x.CommunicationChannelTypeId)
                .Not.Insert()
                .Not.Update()
                .Nullable();
            Map(x => x.DateCreated).Nullable();

            References(x => x.CommunicationChannelType).LazyLoad();
            References(x => x.User).Nullable();
            References(x => x.Product).Nullable();
            References(x => x.Merchant).Nullable();

            HasMany(x => x.Emails)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("CommunicationChannelId");
                //.Fetch.Join();

            HasMany(x => x.Phones)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("CommunicationChannelId");
                //.Fetch.Join();

            HasMany(x => x.Devices)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("CommunicationChannelId");
                //.Fetch.Join();

            HasMany(x => x.NetHttp)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("CommunicationChannelId");
            //.Fetch.Join();

        }
    }
}